package com.nf.health.app.main_intervention.activity;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.http.Act;
import com.nf.health.app.main_intervention.adapter.FoodPlanAdapter;
import com.nf.health.app.main_intervention.bean.MedicinedDietBean;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by hepann on 2016/11/11.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author hepann
 * @Description 膳食计划
 * @email he_pann@163.com
 */

public class FoodPlanActivity extends BaseActivity {
    @Bind(R.id.titlebar_title_tv)
    TextView titlebarTitleTv;
    @Bind(R.id.recycle_view)
    RecyclerView recycleView;
    @Bind(R.id.srl_refresh)
    SwipeRefreshLayout srlRefresh;

    private String mInterventionId;
    private FoodPlanAdapter mAdapter;
    private MedicinedDietBean mDietBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_food_plan);
        ButterKnife.bind(this);
        mInterventionId = getIntent().getStringExtra(Constants.INTERVENTION_ID);
        if (TextUtils.isEmpty(mInterventionId)) {
            showToast("缺少方案id");
            finish();
        }
        initView();
        initData();
    }

    private void initView() {
        titlebarTitleTv.setText("执行方案");
        //recyclerView设置
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        recycleView.setItemAnimator(new DefaultItemAnimator());
        //SwipeRefreshLayout设置
        srlRefresh.setColorSchemeResources(R.color.theme_color, R.color.orange);
        srlRefresh.setEnabled(false);//暂时不用下拉刷新
    }

    private void initData() {
        provider.getMedicineddietById(mInterventionId);
    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {
        super.handleActionSuccess(actionName, object);
        if (Act.Flag.GET_MEDICINEDDIET_BY_ID.equals(actionName)) {
            mDietBean = (MedicinedDietBean) object;
            mAdapter = new FoodPlanAdapter(this, mDietBean);
            recycleView.setAdapter(mAdapter);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}
